# coding: utf-8

import pandas as pd
from sklearn.feature_extraction.text import TfidfTransformer

import src.core.CacheUtils as CacheUtils

transformer = TfidfTransformer()

def tf_dif(data):
    arr = transformer.fit_transform(data).toarray()
    CacheUtils.save_model(transformer, "../../dist/tf_dif_trans.pkl")
    return arr


def tf_dif_df(dataframe):
    values = tf_dif(dataframe.values)
    df = pd.DataFrame(data=values, columns=dataframe.columns)
    return df


def transtorm(data):
    return transformer.transform(data).toarray()
